package com.hn.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hn.mapper.EmpMapper;
import com.hn.pojo.Emp;
import com.hn.pojo.PageBean;
import com.hn.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//import com.github.pagehelper.PageHelper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

//    @Override没参考之前写的
//    public PageBean selectAll(String name, Integer gender, LocalDateTime begin, LocalDateTime end, Integer page, Integer pageSize) {
////        List<Emp> emps = empMapper.selectAll(name, gender, begin, end);
////        Long count= empMapper.count();
////        PageBean p=new PageBean(count,emps);
//        return null;
//    }

    @Override
    public PageBean select(Integer page, Integer pageSize,String name, Short gender, LocalDate begin, LocalDate end) {
        //使用原始方式
//        Integer start= (Integer) ((page-1)*pageSize);
//        Long count = empMapper.count();
//        List<Emp> emps = empMapper.select(start, pageSize);
        //PageBean pageBean=new PageBean(count,emps);
        //使用pageHelper
//        PageHelper.startPage(page,pageSize);
//        Page<Emp> p= (Page<Emp>) empMapper.select();
//        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        //结合pageHelper再条件查询
        PageHelper.startPage(page,pageSize);
        Page<Emp> p= (Page<Emp>) empMapper.select(name,gender,begin,end);
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public void delete(Integer[] ids) {
        empMapper.delete(ids);
    }

    @Override
    public void add(Emp emp) {
        empMapper.add(emp);
    }

    @Override
    public Emp selectById(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }

}
